// antd 按需加载
import { Toast } from '@ant-design/react-native';

import store from '../../../store/store.js'
import * as ActionTypes from '../../../constants/constants.js'
import { isUser, isWxUser, path, saveData, loadData, removeData, requestMessage } from '../../../util/utils.js'
import request from '../../../api/request.js'

export async function register(options) {
    const { dispatch } = this.props
    const loading = Toast.loading('注册中', 0, null, false)
    const res = await request.MemberController.register(options)

    return requestMessage(res, loading, {
        success: '注册成功',
        error: res.data.message
    })
}


export async function sendRegisterAuthCode(options) {
    const { dispatch } = this.props
    const loading = Toast.loading('获取验证码中', 0, null, false)
    const res = await request.MemberController.registerAuthCode(options)
    if (res.data.code == 200) {
        this.setState({
            disable: true,
        });
        let send = 60;
        this.time = setInterval(() => {
            this.setState({
                send: `${send}s后重新获取`,
            });
            send--;
            if (send < 0) {
                clearInterval(this.time);
                this.setState({
                    disable: false,
                    send: '获取验证码',
                });
            }
        }, 1000);
    }
    return requestMessage(res, loading, {
        success: '验证码已发送到您的手机',
        error: res.data.message,
    })
    // callback ? callback(res.data) : null
}

